# -*- coding: utf-8 -*-
'''
模块：生意通-市场分析-流量分析
输入：cookie,hotel_id,hotel_name
输出：totalListExposure #
      totalDetailExposure # 详情页浏览
      orderFillingNum # 订单填写页
      orderSubmitNum # 订单提交成功页
      listTransforDetailRate # 曝光转化率
      detailtoFillingRate # 下单转化率
      fillingtoSubmitRate # 成交转化率
'''
import requests
import json
from fcs import url_request

def main(cookies,hotel_id,hotel_name):
    item={}
    url="http://syt.ctrip.com/api/dataCenter/traffic/queryFlowTransforSummary?hostType=Ebooking"
    header={
        'Content-Type':'application/json'
    }

    # con=requests.post(url=url,cookies=cookies,headers=header).text

    while True:
        try:
            con=url_request.post_url_requests(url=url,cookies=cookies,headers=header,data={})
            json_data = json.loads(con)['data']
            break
        except:
            continue

    # json_data=json.loads(con)['data']
    totalListExposure=json_data['totalListExposure'] # 列表页曝光
    totalDetailExposure=json_data['totalDetailExposure'] # 详情页浏览
    orderFillingNum=json_data['orderFillingNum'] # 订单填写页
    orderSubmitNum=json_data['orderSubmitNum'] # 订单提交成功页

    listTransforDetailRate=json_data['listTransforDetailRate'] # 曝光转化率
    detailtoFillingRate=json_data['detailtoFillingRate'] # 下单转化率
    fillingtoSubmitRate=json_data['fillingtoSubmitRate'] # 成交转化率

    item.update(totalListExposure=totalListExposure)
    item.update(totalDetailExposure=totalDetailExposure)
    item.update(orderFillingNum=orderFillingNum)
    item.update(orderSubmitNum=orderSubmitNum)
    item.update(listTransforDetailRate=listTransforDetailRate)
    item.update(detailtoFillingRate=detailtoFillingRate)
    item.update(fillingtoSubmitRate=fillingtoSubmitRate)

    return item